package com.mbl.base.modular.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mbl.base.modular.mall.constant.GrouponConstant;
import com.mbl.base.modular.mall.entity.Groupon;
import com.mbl.base.modular.mall.mapper.GrouponMapper;
import com.mbl.base.modular.mall.service.IGrouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 团购活动表 服务实现类
 * </p>
 *
 * @author lwj
 * @since 2020-03-22
 */
@Service
public class GrouponServiceImpl extends ServiceImpl<GrouponMapper, Groupon> implements IGrouponService {

    @Override
    public int countGroupon(Long grouponLinkId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("groupon_id", grouponLinkId);
        queryWrapper.ne("status", GrouponConstant.STATUS_NONE);
        return count(queryWrapper);
    }

    @Override
    public boolean hasJoin(Long userId, Long grouponLinkId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("groupon_id", grouponLinkId);
        queryWrapper.ne("status",GrouponConstant.STATUS_NONE);
        return count(queryWrapper) != 0;
    }

    @Override
    public Groupon queryByOrderId(Long orderId) {
        return query().eq("order_id", orderId).one();
    }
}
